package com.css.apps.base.org.action;

import com.css.db.query.QueryCache;
import com.css.util.StringHelper;
import com.css.webbase.webwork.action.AdminAction;
import com.opensymphony.xwork.Action;

import net.sf.json.JSONArray;
/**
 * 预览以保存的自定义组织机构树
 * 
 */
@SuppressWarnings("serial")
public class GetPreviewMini extends AdminAction {

	private String uuid;
	private String exp_series;
	private String exp_orgId;
	private Integer series;

	@Override
	protected String adminGo() {
		QueryCache qc = new QueryCache("select a.exp from SSysOrgTree a " + getWhere());
		setWhere(qc);
		String resStr = (String) qc.list().get(0);
		String str[] = resStr.split("，"); // ，和：均为中文符号
		String prefix[] = new String[str.length];
		String res[] = new String[str.length];
		for (int i = 0; i < str.length; i++) {
			prefix[i] = str[i].split("：")[0];
			if ("series".equals(prefix[i])) {
				res[i] = str[i].split("：")[1];
				exp_series = (res[i]);
			} else if ("parentOrgId".equals(prefix[i])) {
				res[i] = str[i].split("：")[1];
				exp_orgId = (res[i]);
			}
		}
		series = Integer.valueOf(exp_series);
		JSONArray orgTree = GetPreviewTree.getOrgTree(series, exp_orgId);
		result = orgTree.toString();

		return Action.SUCCESS;
	}

	public String getWhere() {
		StringBuffer sb = new StringBuffer("where 1 = 1");
		if (StringHelper.isNotEmpty(uuid))
			sb.append(" and uuid=:uuid ");
		return sb.toString();
	}

	public void setWhere(QueryCache qc) {
		if (StringHelper.isNotEmpty(uuid))
			qc.setParameter("uuid", uuid);
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public String getExp_series() {
		return exp_series;
	}

	public void setExp_series(String exp_series) {
		this.exp_series = exp_series;
	}

	public String getExp_orgId() {
		return exp_orgId;
	}

	public void setExp_orgId(String exp_orgId) {
		this.exp_orgId = exp_orgId;
	}

	public Integer getSeries() {
		return series;
	}

	public void setSeries(Integer series) {
		this.series = series;
	}

}
